layui.use(['form', 'table', 'laydate', 'layarea', 'tableSelect'], function () {
    let $ = layui.jquery,
        form = layui.form,
        table = layui.table;

    let id_arr=$.getQueryVariable('id_arr')


    /*订单列表*/
    table.render(
        {
            elem: '#currentTableId',
            url: '/admin/OrderData/index?action=ajax&id_arr='+id_arr,
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                $('#countNum').html(res.count);

            },
            toolbar: '#toolbarDemo',
            defaultToolbar: [ 'exports', 'print'],
            cols: [
                [
                {field: 'receive_name', title: '姓名' ,width:100},
                    // {field: 'order_number', title: 'dd' },
                {field: 'receive_phone', title: '电话' ,width:120},
                {field: 'address_all', title: '地址' ,width:370},
                {field: 'create_time', title: '下单时间' ,width:180},
                {field: 'bzipro_arr', title: '商品列表', templet:"#Bizprostatus",style:"white-space:wrap"},
                {field: 'pay_price', title: '订单金额',width:90},
                {field: 'data_status', title: '订单状态',templet:"#Tplstatus",width:90},
                {title: '操作', toolbar: '#currentTableBar',width:80},
                ],
            ],

             limits: [10, 15, 20, 25, 30, 50, 100],
            limit: 10,
            page: true,
            skin: 'line,row',
            done: function (res, curr, count) {

            }
        }
    );



    table.on('tool(currentTableFilter)', function (obj) {

        let data = obj.data;

        if (obj.event === 'orderdetail') {
            let index = layer.open({
                title: '订单详情',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: '/admin/OrderData/DataDetail?mo_id=' + data.mo_id,
                end: function () {
                    /*删除session无用图片*/
                    $.ajax({
                        url: '/admin/order/clearSession',
                        type: 'post',
                        dataType: 'json',
                    });
                }
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
        }

    });


    // 监听搜索操作
    form.on('submit(data-search-btn)', function (data) {
        submitInfo();
    });
    form.on('select(selectInfo)', function (data) {
        submitInfo();
    });

    $("input[name='keywords']").on('blur',function (re) {
        submitInfo();
    })



    function submitInfo() {
        let param = {};
        let t = $('#formInfo [name]');

        $.each(t, function () {
            param[this.name] = this.value;
        });

        //let result = JSON.stringify(d);

        //执行搜索重载
        table.reload('currentTableId', {
            page: {
                curr: 1
            }
            , where: {
                //searchParams: result
                param
            }
        }, 'data');
        return false;
    };
});
